#include "../comm.h"
class Solution {
public:
    int wateringPlants(vector<int>& plants, int capacity) {
        int ans = 0;
        int now = capacity, n = plants.size();
        for(int i = 0; i < n; ++i)
        {
            ++ans;
            if(now >= plants[i])
                now -= plants[i];
            else
                now = capacity - plants[i], ans += i * 2;
        }
        return ans;
    }
};